﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Opennav.MapGenerator.Map.Labels;
using System.IO;
using Opennav.MapGenerator.Locator;

namespace Opennav.MapGenerator.Map.Locations
{
    public class Region
    {
        public Region(short id, GeoArea area, Country country, Label label)
        {
            this.Id = id;
            this.Area = area;
            this.Country = country;
            this.Label = label;
        }

        public Region(short id, GeoArea area, Region parentRegion, Label label)
        {
            this.Id = id;
            this.Area = area;
            this.Country = parentRegion.Country;
            this.ParentRegion = parentRegion;
            this.Label = label;
        }

        public short Id { get; private set; }

        public GeoArea Area { get; private set; }

        public Country Country { get; private set; }

        public Region ParentRegion { get; private set; }

        public Label Label { get; private set; }

        public void Write(Stream stream)
        {
            BinaryWriter writer = new BinaryWriter(stream);
            writer.Write((uint)(Label.Offset & 0x7fffffff));
            byte countryId = Country.Id;
            short parentRegionId = -1;
            if (ParentRegion != null)
            {
                parentRegionId = ParentRegion.Id;
            }
            writer.Write(countryId);
            writer.Write(parentRegionId);
        }
    }
}
